from bs4 import BeautifulSoup
import requests
# https://www.youdao.com/w/eng/word/
def get_pronounce(spelling):
    # url = 'https://www.youdao.com/w/eng/word/'
    url='https://www.youdao.com/w/eng/'+spelling+'/'
    r = requests.get(url)
    demo = r.text  # 服务器返回响应

    soup = BeautifulSoup(demo, "html.parser")
    """
    demo 表示被解析的html格式的内容
    html.parser表示解析用的解析器
    """
    # print(soup)  # 输出响应的html对象
    # print(soup.prettify())  # 使用prettify()格式化显示输出
    pronounce =""

    for i in soup.find_all('span'):
        try:
            if i.attrs['class'][0] == 'phonetic':
                pronounce = str(i.string)
                break # 只保留 英文发音
        except KeyError:
            pass
    return pronounce

if __name__ == '__main__':
    print(get_pronounce('word'))